<?php

/**
 * Class AccountController
 */
class AdminController extends BaseController
{

    public function __construct(){
        parent::__construct();
//权限控制
        if (Session::has(UserEnum::ADMIN_USER_KEY)) {
            $admin_info = Session::get(UserEnum::ADMIN_USER_KEY);
            $action = Route::currentRouteAction();
            list($class, $method) = explode('@', $action);
//            $user_info->role_id = UserEnum::USER_ROLE_ADMINISTRATOR;
            $aMenus = AdminMenuEnum::getUserMenus($admin_info->role_id);
            //dd($method);
            if (!in_array($method, $aMenus)) {
                $page = AccountService::instance()->getDefaultPage($admin_info->role_id);
                    echo "<script>alert('您的权限不够');location='/admin$page';</script>";
            }
        }else{
            $action = Route::currentRouteAction();
            list($class, $method) = explode('@', $action);
            if ($method == 'Login') {
                return Redirect::to("/admin/");
            }else if($method == 'DisposeLogin'){
                return Redirect::to("/admin/depose_login");
            }else if( $method == 'CacheCate'){
                return Redirect::to("/admin/cache_cate");
            }
        }
    }
    /**
     * 登录
     * @author  fyl
     */
    public function Login(){

        return $this->view('admin.login');
    }

    /**
     * 登录请求
     * @author  fyl
     */
    public function DisposeLogin()
    {
        #接受参数
        $paramObj                   =          new stdClass();
        $paramObj->username         =          $this->getParam('username');          //用户名
        $paramObj->password         =          $this->getParam('password');          //密码
        $paramObj->captcha          =          $this->getParam('captcha');           //验证码

        try{
            AdminService::instance()->LoginValidator($paramObj);
            return Redirect::to('/admin/manage_product');
        }catch (Exception $e){
            return Redirect::to('/admin');
        }
    }

    /**
     * 生成验证码
     * @author fyl
     * @date 2016-03-05
     */
    public function Captcha()
    {
        CaptchaService::instance()->create();
    }






    /**
     * 資訊列表
     * @return mixed
     * @author fyl
     * @date 2016-04-01
     */
    public function NewsList()
    {
        $info = AdminService::instance()->NewsList();
        return $this->view("admin.news_list")->with('lists',$info);
    }

    /**
     * 資訊录入
     * @return mixed
     * @author fyl
     * @date 2016-04-01
     */
    public function NewsImport()
    {
        #接收参数
        $paramObj = new stdClass();
        $paramObj->id = $this->getParam('zx_id');
        if(!empty($paramObj->id)){
            $info = AdminService::instance()->SelectOneNews($paramObj);
            return $this->view('admin.news_import')->with(["news"=>$info,"type"=>InformationEnum::$information_types]);
        }else{
            return $this->view('admin.news_import')->with('type',InformationEnum::$information_types);
        }
    }

    /**
     * 咨讯添加
     * @author  fyl
     * @date    2016-03-31
     */
    public function NewsModifyAction()
    {
        #接收参数
        if(Request::isMethod('POST'))
        {
            $paramObj                       =          new stdClass();
            $paramObj->title                =          $this->getParam('title');
            $paramObj->author               =          $this->getParam('author');
            $paramObj->source               =          $this->getParam('source');
            $paramObj->keywords             =          $this->getParam('keywords');
            $paramObj->thumb_img1           =          $this->getParam('thumb_img1');
//            $paramObj->thumb_img2           =          $this->getParam('thumb_img2');
//            $paramObj->thumb_img3           =          $this->getParam('thumb_img3');
            $paramObj->cate                 =          $this->getParam('cate');
            $paramObj->content              =          $this->getParam('content');
            $paramObj->is_index             =          $this->getParam('is_index');

            #逻辑操作
            AdminService::instance()->AddNews($paramObj);
            LogService::instance()->write(['content' => '添加资讯'.$paramObj->title, 'type' => '资讯管理']);
            return Redirect::to('/admin/news_list');
        }
    }

    /**
     * 资讯修改
     * @author  fyl
     * @date    2016-04-01
     */
    public function NewsUpdateAction()
    {
        #接收参数
        if(Request::isMethod('POST'))
        {
            $paramObj                       =          new stdClass();
            $paramObj->zx_id                =          $this->getParam('zx_id');
            $paramObj->title                =          $this->getParam('title');
            $paramObj->author               =          $this->getParam('author');
            $paramObj->source               =          $this->getParam('source');
            $paramObj->keywords             =          $this->getParam('keywords');
            $paramObj->thumb_img1           =          $this->getParam('thumb_img1');
//            $paramObj->thumb_img2           =          $this->getParam('thumb_img2');
//            $paramObj->thumb_img3           =          $this->getParam('thumb_img3');
            $paramObj->cate                 =          $this->getParam('cate');
            $paramObj->content              =          $this->getParam('content');
            $paramObj->thumb_img1_old        =          $this->getParam('thumb_img1_old');        //展示图1
//            $paramObj->thumb_img2_old        =          $this->getParam('thumb_img2_old');        //展示图2
//            $paramObj->thumb_img3_old        =          $this->getParam('thumb_img3_old');        //展示图3
            $paramObj->is_index             =          $this->getParam('is_index');
            #逻辑操作
            AdminService::instance()->UpdateNews($paramObj);
            LogService::instance()->write(['content' => '修改资讯'.$paramObj->title, 'type' => '资讯管理']);
            return Redirect::to('/admin/news_list');
        }
    }



    /**
     * 資訊删除
     * @return mixed
     * @author fyl
     * @date 2016-04-01
     */
    public function NewsDeleteAction()
    {
        #接收参数
        $paramObj = new stdClass();
        $paramObj->zx_id = $this->getParam('zx_id');
        $state = AdminService::instance()->DeleteOneNews($paramObj);
        $title = AdminService::instance()->SelectOneNews($paramObj);
        LogService::instance()->write(['content' => '修改资讯'.$title->title, 'type' => '资讯管理']);
        if($state == 1){
            $rs['code'] = 1;
        }else{
            $rs['code'] = 0;
        }
        return $rs;
       // $this->rest->success(['state' => $state],ErrorCodeEnum::STATUS_SUCCESS,'刪除成功！');
    }

    /**
     *咨询ajax返回模板
     * @return mixed
     * @author fyl
     * @date 2016-03-30
     */
    public function NewsServiceAjax()
    {
        $info = AdminService::instance()->NewsList();
        $this->viewAjax('admin.ajaxTemplates.news_list_part')->with('lists',$info);
    }




    /**
     * 仓储服务
     * @return mixed
     * @author lizhongpeng
     * @date 2016-03-31
     */
    public function StorageService()
    {
        $info = AdminService::instance()->ShowStorage();
        return $this->view("admin.storage_service")->with('info',$info);
    }
    /**
     * 仓储录入
     * @return mixed
     * @author lizhongpeng
     * @date 2016-04-01
     */
    public function StorageImport()
    {
        return $this->view("admin.storage_import");
    }

    /**
     * 仓储添加编辑
     */
    public function StorageEdit()
    {
        if(Request::isMethod('POST'))
        {
            #收集信息
            $paramObj                        =          new stdClass();
            $paramObj->storage_id            =          $this->getParam('storage_id');            //仓储id
            $paramObj->storage_name          =          $this->getParam('storage_name');          //仓库名称
            $paramObj->storage_address       =          $this->getParam('storage_address');       //仓库地址
            $paramObj->pro                 =          $this->getParam('pro');                          //省
            $paramObj->city             =          $this->getParam('city');                             //市
            $paramObj->coun             =          $this->getParam('coun');                              //县
            $paramObj->storage_phone             =          $this->getParam('storage_phone');        //仓库电话
            $paramObj->storage_work_time             =          $this->getParam('storage_work_time'); //换单时间
            #逻辑操作
            if(empty($paramObj->storage_id)){
                AdminService::instance()->StorageAdd($paramObj);
                    LogService::instance()->write(['content' => '添加仓储'.$paramObj->storage_name, 'type' => '仓促服务']);
            }else{
                AdminService::instance()->StorageUp($paramObj);
                    LogService::instance()->write(['content' => '修改仓储'.$paramObj->storage_name, 'type' => '仓促服务']);
            }
            return Redirect::to('/admin/storage_service');
        }
        else
        {
            $id = $this->getParam('storage_id');
            $info = AdminService::instance()->GetStorageInfo($id);
            return $this->view('admin.storage_import')->with('storage',$info);

        }

    }

    /**
     * 仓储列表删除
     */
    public function StorageDelete()
    {
        #收集信息
        $aData              =     new stdClass();
        $aData->id          =     $this->getParam('storage_id');

        #仓储名称
        $storage_name = AdminService::instance()->GetStorageInfo($aData->id)->storage_name;
        #逻辑操作
        $state = AdminService::instance()->StorageDelete($aData);
        LogService::instance()->write(['content' => '删除仓储'.$storage_name, 'type' => '仓储服务']);
        $this->rest->success(['state' => $state],ErrorCodeEnum::STATUS_SUCCESS,'刪除成功！');

    }

    /**
     * 仓储线路ajax返回模板
     * @return mixed
     * @author lzhp
     * @date 2016-04-01
     */
    public function StorageServiceAjax()
    {
        $info = AdminService::instance()->ShowStorage();
        return $this->viewAjax('admin.ajaxTemplates.storage_list_part')->with('info',$info);

    }


    /*---------------------------------------------钢厂-----------------------------------------------*/


    /**
     * 钢厂列表
     * @return mixed
     * @author 刘玉超
     * @date 2016-03-31
     */
    public function FactoryList()
    {
        $info = AdminService::instance()->FactoryList();
        return $this->view("admin.factory_list")->with('info',$info);
    }

    /**
     * 钢厂
     * @return mixed
     * @author lizhongpeng
     * @date 2016-04-01
     */
    public function FactoryImport()
    {
        return $this->view("admin.factory_import");
    }
    /**
     * 仓储添加编辑
     */
    public function FactoryEdit()
    {
        if(Request::isMethod('POST'))
        {
            #收集信息
            $paramObj                        =          new stdClass();
            $paramObj->factory_id            =          $this->getParam('factory_id');
            $paramObj->factory_name          =          $this->getParam('factory_name');
            $paramObj->contact_name          =          $this->getParam('contact_name');
            $paramObj->address       =          $this->getParam('address');
            $paramObj->email       =          $this->getParam('email');
            $paramObj->postcord     =          $this->getParam('postcord');
            $paramObj->remarks     =          $this->getParam('remarks');
            $paramObj->pro                 =          $this->getParam('pro');                          //省
            $paramObj->city             =          $this->getParam('city');                             //市
            $paramObj->coun             =          $this->getParam('coun');                              //县
            $paramObj->phone             =          $this->getParam('phone');
            $paramObj->picture             =          $this->getParam('picture');
            $paramObj->picture_old             =          $this->getParam('picture_old');
            $paramObj->recommend                =     $this->getParam('recommend');
            #逻辑操作
            if(empty($paramObj->factory_id)){
                AdminService::instance()->FactoryAdd($paramObj);
                LogService::instance()->write(['content' => '添加钢厂'.$paramObj->factory_name, 'type' => '钢厂']);
            }else{
                AdminService::instance()->FactoryUp($paramObj);
                LogService::instance()->write(['content' => '修改钢厂'.$paramObj->factory_name, 'type' => '钢厂']);
            }
            return Redirect::to('/admin/factory_list');
        }
        else
        {
            $id = $this->getParam('factory_id');
            $info = AdminService::instance()->GetFactoryInfo($id);
            return $this->view('admin.factory_import')->with('factory',$info);

        }

    }

    /**
     * 仓储列表删除
     */
    public function FactoryDelete()
    {
        #收集信息
        $aData              =     new stdClass();
        $aData->id          =     $this->getParam('factory_id');

        #仓储名称
        $factory_name = AdminService::instance()->GetFactoryInfo($aData->id)->factory_name;
        #逻辑操作
        $state = AdminService::instance()->FactoryDelete($aData);
        LogService::instance()->write(['content' => '删除钢厂'.$factory_name, 'type' => '钢厂']);
        $this->rest->success(['state' => $state],ErrorCodeEnum::STATUS_SUCCESS,'刪除成功！');

    }

    /**
     * 钢厂ajax返回模板
     * @return mixed
     * @author lzhp
     * @date 2016-04-01
     */
    public function FactoryServiceAjax()
    {
        $info = AdminService::instance()->ShowFactory();
        return $this->viewAjax('admin.ajaxTemplates.factory_list_part')->with('info',$info);

    }





    /*----------------------------------------------产品----------------------------------------------*/
    /**
     * 商品列表
     * @return mixed
     * @author fyl
     * @date 2016-04-04
     */
    public function ManageProduct(){
        $info = AdminService::instance()->ShowProduct();
        return $this->view('admin.manage_product')->with('product_list',$info);
    }

    /**
     * 审核列表
     * @return mixed
     * @author fyl
     * @date 2016-05-24
     */
    public function ProductExamineList(){
        $info = AdminService::instance()->ProductExamineList();
        return $this->view('admin.product_examine_list')->with('product_list',$info);
    }

    /**
     * 产品录入
     * @return mixed
     * @author fyl
     * @date 2016-04-04
     */
    public function ProductImport()
    {
        #接收参数
        $paramObj = new stdClass();
        $paramObj->product_id = $this->getParam('product_id');
        if(!empty($paramObj->product_id)){
            $info = AdminService::instance()->SelectOneProduct($paramObj);
            $brand = AdminService::instance()->SelectBrand();
            $spec = AdminService::instance()->SelectSpec($info->product_brand);
            $material = AdminService::instance()->SelectMaterial();
            $storage = AdminService::instance()->SelectStorage();
            $factory = AdminService::instance()->SelectFactory();
            return $this->view('admin.product_import')->with(['product'=>$info,'brand'=>$brand,'material'=>$material,'storage'=>$storage,'factory'=>$factory,'spec'=>$spec]);
        }else{
            $brand = AdminService::instance()->SelectBrand();
            $material = AdminService::instance()->SelectMaterial();
            $storage = AdminService::instance()->SelectStorage();
            $factory = AdminService::instance()->SelectFactory();
            return $this->view('admin.product_import')->with(['brand'=>$brand,'material'=>$material,'storage'=>$storage,'factory'=>$factory]);
        }
    }
    /**
     *分类联动
     */
    public function linkage(){
        $paramObj = new stdClass();
        $paramObj->id = $this->getParam('id');
        $info = AdminService::instance()->linkage($paramObj->id);
        return $info;


    }

    /**
     * 产品审核
     * @return mixed
     * @author fyl
     * @date 2016-05-24
     */
    public function ProductExamine()
    {
        #接收参数
        $paramObj = new stdClass();
        $paramObj->product_id = $this->getParam('product_id');
        $info = AdminService::instance()->SelectOneProduct($paramObj);
        $yiname = AdminService::instance()->GetName($info->category);
        $ername = AdminService::instance()->GetName($info->classes);
        $sanname = AdminService::instance()->GetName($info->quality);
        $info->category = $yiname->cate_name;
        $info->classes = $ername->cate_name;
        $info->quality = $sanname->cate_name;

         /*     $band  = AdminService::instance()->ShowProductBrand();
           $cate  = AdminService::instance()->ShowProductCateQuality();
      /$area  = AdminService::instance()->ShowProductArea();
           $spec  = AdminService::instance()->ShowProductSpec();
           $level = AdminService::instance()->ShowProductLevel();*/
            return $this->view('admin.product_examine')->with('product',$info);

    }


    /**
     * 产品审核
     * @author  fyl
     * @date    2016-08-16
     */
    public function ProductExamineAction()
    {
        #接收参数
        if(Request::isMethod('POST'))
        {
            $paramObj                       =          new stdClass();
            $paramObj->product_id           =          $this->getParam('product_id');     //审核商品ID
            $paramObj->status               =          $this->getParam('status');         //审核状态
            #逻辑操作
            $status = AdminService::instance()->UpdateStatus($paramObj);
            LogService::instance()->write(['content' => '审核产品ID为'. $paramObj->product_id, 'type' => '产品管理']);
            return $status;
        }
    }


    /**
     * 产品添加
     * @author  fyl
     * @date    2016-04-05
     */
    public function ProductImportAction()
    {
        #接收参数
        if(Request::isMethod('POST'))
        {
            $paramObj                               =          new stdClass();
            $paramObj->product_id                   =          $this->getParam('product_id');           //ID
            $paramObj->product_brand                =          $this->getParam('product_brand');        //品名
            $paramObj->product_material             =          $this->getParam('product_material');     //材质
            $paramObj->product_spec                 =          $this->getParam('product_spec');         //规格
            $paramObj->product_price                =          $this->getParam('product_price');        //价格
            $paramObj->real_stock                   =          $this->getParam('real_stock');           //库存
            $paramObj->piece_weight                 =          $this->getParam('piece_weight');         //件重
            $paramObj->storage                      =          $this->getParam('storage');              //仓库
            $paramObj->factory                      =          $this->getParam('factory');              //钢厂
            $paramObj->duty_people                  =          $this->getParam('duty_people');          //负责人
            $paramObj->remarks                      =          $this->getParam('remarks');              //备注
            $paramObj->category                     =          $this->getParam('category');              //备注
            #逻辑操作
            AdminService::instance()->AddProduct($paramObj);
            LogService::instance()->write(['content' => '产品添加'. $paramObj->product_brand.'-'.$paramObj->product_material.'-'.$paramObj->product_spec, 'type' => '产品管理']);
            return Redirect::to('/admin/manage_product');
        }
    }


    /**
     * 产品删除
     * @return mixed
     * @author fyl
     * @date 2016-04-13
     */
    public function ProductDeleteAction()
    {
        #接收参数
        $paramObj = new stdClass();
        $paramObj->product_id = $this->getParam('product_id');
        $product = AdminService::instance()->SelectOneProduct($paramObj);
        $state = AdminService::instance()->DeleteOneProduct($paramObj);
        LogService::instance()->write(['content' => '产品删除'. $product->product_brand.'-'.$product->product_material.'-'.$product->product_spec, 'type' => '产品管理']);
        $this->rest->success(['state' => $state],ErrorCodeEnum::STATUS_SUCCESS,'刪除成功！');
    }

    /**
     * 产品ajax返回模板
     * @return mixed
     * @author fyl
     * @date 2016-03-30
     */
    public function ProductServiceAjax()
    {
        $info = AdminService::instance()->ShowProduct();
        $this->viewAjax('admin.ajaxTemplates.Product_list_part')->with('product_list',$info);
    }


    /**
     * 产品品牌列表
     * @return mixed
     * @author fyl
     * @date 2016-04-04
     */
    public function ProductBrand(){
        $info = AdminService::instance()->ShowProductBrand();

        foreach($info as $key =>$info1){
            $category_name = AdminService::instance()->SelectCategory($info1->cate_id);
            $info[$key]->cate_name = $category_name->category_name;
        }
        return $this->view('admin.product_brand')->with(['brand'=>$info]);
    }

    /**
     * 产品品名录入
     * @return mixed
     * @author fyl
     * @date 2016-04-04
     */
    public function ProductBrandImport()
    {
        #接收参数
        $paramObj = new stdClass();
        $paramObj->brand_id = $this->getParam('brand_id');
        if(!empty($paramObj->brand_id)){
            $info = AdminService::instance()->SelectOneProductBrand($paramObj);
            $category = AdminService::instance()->GetCategory();
            return $this->view('admin.product_brand_import')->with(['brand'=>$info,'category'=>$category]);
        }else{
            $category = AdminService::instance()->GetCategory();
            return $this->view('admin.product_brand_import')->with('category',$category);
        }
    }

    /**
     * 品牌添加
     * @author  fyl
     * @date    2016-03-31
     */
    public function ProductBrandImportAction()
    {
        #接收参数
        if(Request::isMethod('POST'))
        {
            $paramObj                       =          new stdClass();
            $paramObj->brand_id             =          $this->getParam('brand_id');
            $paramObj->brand_name           =          $this->getParam('brand_name');
            $paramObj->cate_id           =          $this->getParam('category_name');
            #逻辑操作
            AdminService::instance()->AddProductBrand($paramObj);
            LogService::instance()->write(['content' => '品牌添加/修改'. $paramObj->brand_name, 'type' => '品牌管理']);
            return Redirect::to('/admin/product_brand');
        }
    }



    /**
     * 品牌删除
     * @return mixed
     * @author fyl
     * @date 2016-04-01
     */
    public function ProductBrandDeleteAction()
    {
        #接收参数
        $paramObj = new stdClass();
        $paramObj->brand_id = $this->getParam('brand_id');
        $brand = AdminService::instance()->SelectOneProductBrand($paramObj);
        $state = AdminService::instance()->DeleteOneProductBrand($paramObj);
        if($state){
            LogService::instance()->write(['content' => '品牌删除'. $brand->brand_name, 'type' => '品牌管理']);
            $this->rest->success(['state' => $state],ErrorCodeEnum::STATUS_SUCCESS,'刪除成功！');
        }else{
            $this->rest->success(['state' => $state],ErrorCodeEnum::STATUS_SUCCESS,'刪除失败！');
        }

    }

    /**
     * 品牌ajax返回模板
     * @return mixed
     * @author fyl
     * @date 2016-04-05
     */
    public function ProductBrandAjax()
    {
        $info = AdminService::instance()->ShowProductBrand();
        $this->viewAjax('admin.ajaxTemplates.product_brand_part')->with('brand',$info);
    }



    /**
     * 产品材质列表
     * @return mixed
     * @author fyl
     * @date 2016-04-04
     */
    public function ProductMaterial(){
        $info = AdminService::instance()->ShowProductMaterial();
        return $this->view('admin.product_material')->with('material',$info);
    }

    /**
     * 材质是否存在
     * @return mixed
     * @author fyl
     * @date 2016-08-16
     */
    public function ProductMaterialIs(){
        #接收参数
        $m_name = $this->getParam('m_name');
        $status = AdminService::instance()->ProductMaterialIs($m_name);
        return $status;
    }

    /**
     * 品名是否存在
     * @return mixed
     * @author fyl
     * @date 2016-08-16
     */
    public function ProductBrandIs(){
        #接收参数
        $brand_name = $this->getParam('brand_name');
        $status = AdminService::instance()->ProductBrandIs($brand_name);
        return $status;
    }

    /**
     * 规格
     * @return mixed
     * @author fyl
     * @date 2016-08-16
     */
    public function GetSpec(){
        #接收参数
        $id = $this->getParam('id');
        return AdminService::instance()->GetSpec($id);

    }


    /**
     * 产品材质录入
     * @return mixed
     * @author fyl
     * @date 2016-04-04
     */
    public function ProductMaterialImport()
    {
        #接收参数
        $paramObj = new stdClass();
        $paramObj->m_id = $this->getParam('m_id');
        if(!empty($paramObj->m_id)){
            $info = AdminService::instance()->SelectOneProductMaterial($paramObj);
            return $this->view('admin.product_material_import')->with('material',$info);
        }else{
            return $this->view('admin.product_material_import');
        }
    }

    /**
     * 材质添加
     * @author  fyl
     * @date    2016-03-31
     */
    public function ProductMaterialImportAction()
    {
        #接收参数
        if(Request::isMethod('POST'))
        {
            $paramObj                       =          new stdClass();
            $paramObj->m_id             =          $this->getParam('m_id');
            $paramObj->m_name           =          $this->getParam('m_name');
            $paramObj->m_remarks           =          $this->getParam('m_remarks');
            #逻辑操作
            AdminService::instance()->AddProductMaterial($paramObj);
            LogService::instance()->write(['content' => '品牌添加/修改'. $paramObj->m_name, 'type' => '品牌管理']);
            return Redirect::to('/admin/product_material');
        }
    }



    /**
     * 材质删除
     * @return mixed
     * @author fyl
     * @date 2016-04-01
     */
    public function ProductMaterialDeleteAction()
    {
        #接收参数
        $paramObj = new stdClass();
        $paramObj->m_id = $this->getParam('m_id');
        $material = AdminService::instance()->SelectOneProductMaterial($paramObj);
        $state = AdminService::instance()->DeleteOneProductMaterial($paramObj);
        if($state){
            LogService::instance()->write(['content' => '品牌删除'. $material->m_name, 'type' => '材质管理']);
            $this->rest->success(['state' => $state],ErrorCodeEnum::STATUS_SUCCESS,'刪除成功！');
        }else{
            $this->rest->success(['state' => $state],ErrorCodeEnum::STATUS_SUCCESS,'刪除失败！');
        }

    }

    /**
     * 材质ajax返回模板
     * @return mixed
     * @author fyl
     * @date 2016-04-05
     */
    public function ProductMaterialAjax()
    {
        $info = AdminService::instance()->ShowProductMaterial();
        $this->viewAjax('admin.ajaxTemplates.product_material_part')->with('material',$info);
    }



    /**
     * 产品分类列表
     * @return mixed
     * @author fyl
     * @date 2016-04-04
     */
    public function ProductCate(){
        $info = AdminService::instance()->ShowProductCateAll();
        return $this->view('admin.product_cate')->with('cate',$info);
    }

    /**
     * 缓存产品分类列表
     * @return mixed
     * @author fyl
     * @date 2016-06-21
     */
    public function CacheCate(){
         AdminService::instance()->CacheCate();
    }

    /**
     * 产品类型录入
     * @return mixed
     * @author fyl
     * @date 2016-04-04
     */
    public function ProductCateImport()
    {
        #接收参数
        $paramObj = new stdClass();
        $paramObj->cate_id = $this->getParam('cate_id');
        $paramObj->length = $this->getParam('length');
        if(!empty($paramObj->cate_id)){
            $info = AdminService::instance()->SelectOneProductCate($paramObj);
            if($paramObj->length == 1){
                return $this->view('admin.product_cate_import')->with('productcate',$info);
            }elseif($paramObj->length == 2){
                $c = AdminService::instance()->ShowProductCate();
                return $this->view('admin.product_class_import')->with(['cate'=>$c,'productcate'=>$info]);
            }elseif($paramObj->length == 3){
                $q = AdminService::instance()->ShowProductCateClasses();
                return $this->view('admin.product_quality_import')->with(['cate'=>$q,'productcate'=>$info]);
            }
        }else{
            return $this->view('admin.product_cate_import');
        }
    }

    /**
     * 分类，品类，材质修改
     * @author  fyl
     * @date    2016-04-05
     */
    public function ProductCateUpdateAction()
    {
        #接收参数
        if(Request::isMethod('POST'))
        {
            $paramObj                           =          new stdClass();
            $paramObj->cate_id                  =          $this->getParam('cate_id');
            $paramObj->length                   =          $this->getParam('length');
            $paramObj->cate_name                =          $this->getParam('cate_name');
            $paramObj->parent_id                =          $this->getParam('parent_id');
          //  $paramObj->remark                   =          $this->getParam('remark');
            $paramObj->rank                     =          $this->getParam('rank');
            #逻辑操作
            AdminService::instance()->addProductCate($paramObj);
            LogService::instance()->write(['content' => '分类，品类，材质修改'. $paramObj->cate_name, 'type' => '分类，品类，材质管理']);
            return Redirect::to('/admin/product_cate');
        }
    }


    /**
     * 类型删除
     * @return mixed
     * @author fyl
     * @date 2016-04-01
     */
    public function ProductCateDeleteAction()
    {
        #接收参数
        $paramObj = new stdClass();
        $paramObj->cate_id = $this->getParam('cate_id');
        $state = AdminService::instance()->DeleteOneProductCate($paramObj);
        LogService::instance()->write(['content' => '分类，品类，材质修改'. $paramObj->cate_id , 'type' => '分类，品类，材质管理']);
        $this->rest->success(['state' => $state],ErrorCodeEnum::STATUS_SUCCESS,'刪除成功！');
    }

    /**
     * 类型ajax返回模板
     * @return mixed
     * @author fyl
     * @date 2016-04-05
     */
    public function ProductCateAjax()
    {
        $info = AdminService::instance()->ShowProductCateAll();
        $this->viewAjax('admin.ajaxTemplates.product_cate_part')->with('cate',$info);
    }



    /**
     * 产品规格录入
     * @return mixed
     * @author fyl
     * @date 2016-04-04
     */
    public function ProductSpecImport()
    {
        $cate = AdminService::instance()->ShowProductCateQuality();
        return $this->view('admin.product_spec_import')->with('quality',$cate);
    }

    /**
     * 规格入库
     * @author  fyl
     * @date    2016-04-04
     */
    public function ProductSpecImportAction()
    {
        #接收参数
        if(Request::isMethod('POST'))
        {
            $paramObj                            =          new stdClass();
            $paramObj->spec_name                =          $this->getParam('spec_name');
            $paramObj->quality                   =          $this->getParam('quality');
            $paramObj->sort_by                   =          $this->getParam('sort_by');
            #逻辑操作
            AdminService::instance()->AddProductSpec($paramObj);
            LogService::instance()->write(['content' => '规格添加'. $paramObj->spec_name , 'type' => '规格管理']);
            return Redirect::to('/admin/product_spec_import');
        }
    }

    /**
     * 产品等级录入
     * @return mixed
     * @author fyl
     * @date 2016-04-04
     */
    public function ProductLevelImport()
    {
        $cate = AdminService::instance()->ShowProductCateQuality();
        return $this->view('admin.product_level_import')->with('quality',$cate);
    }

    /**
     * 等级入库
     * @author  fyl
     * @date    2016-04-04
     */
    public function ProductLevelImportAction()
    {
        #接收参数
        if(Request::isMethod('POST'))
        {
            $paramObj                            =          new stdClass();
            $paramObj->level_name                =          $this->getParam('level_name');
            $paramObj->quality                   =          $this->getParam('quality');
            $paramObj->sort_by                   =          $this->getParam('sort_by');
            #逻辑操作
            AdminService::instance()->AddProductLevel($paramObj);
            LogService::instance()->write(['content' => '等级添加'.$paramObj->level_name , 'type' => '等级管理']);
            return Redirect::to('/admin/product_level_import');
        }
    }

    /**
     * 产品材质录入
     * @return mixed
     * @author fyl
     * @date 2016-04-04
     */
    public function ProductQualityImport()
    {
        $info = AdminService::instance()->ShowProductCateClasses();
        return $this->view('admin.product_quality_import')->with('cate',$info);
    }


    /**
     * 分类入库
     * @author  fyl
     * @date    2016-04-04
     */
    public function ProductCateImportAction()
    {
        #接收参数
        if(Request::isMethod('POST'))
        {
            $paramObj                           =          new stdClass();
            $paramObj->cate_id                  =          $this->getParam('cate_id');
            $paramObj->length                   =          $this->getParam('length');
            $paramObj->cate_name                =          $this->getParam('cate_name');
            $paramObj->parent_id                =          $this->getParam('parent_id');
            $paramObj->rank                     =          $this->getParam('rank');
            #逻辑操作
            AdminService::instance()->AddProductCate($paramObj);
            LogService::instance()->write(['content' => '材料添加'. $paramObj->cate_name , 'type' => '材料管理']);
            if($paramObj->length == 1){
                return Redirect::to('/admin/product_cate_import');
            }else if($paramObj->length == 2){
                return Redirect::to('/admin/product_class_import');
            }else{
                return Redirect::to('/admin/product_quality_import');
            }

        }
    }

    /**
     * 产品品类录入
     * @return mixed
     * @author fyl
     * @date 2016-04-04
     */
    public function ProductClassImport()
    {
        $info = AdminService::instance()->ShowProductCate();
        return $this->view('admin.product_class_import')->with('cate',$info);
    }


    /**
     * 文章
     * @return mixed
     * @author lzhp
     * @date 2016-04-01
     */
    public function ArticleList()
    {
        $info = AdminService::instance()->ArticleList();
        return $this->view('admin.article_list')->with('info', $info);
    }

    /**
     * 文章删除
     */
    public function ArticleDelete()
    {
        #收集信息
        $aData = new stdClass();
        $aData->id = $this->getParam('help_id');

        $title = AdminService::instance()->GetArticleId($aData->id)->title;
        #逻辑操作
        $state = AdminService::instance()->ArticleDelete($aData);
        LogService::instance()->write(['content' => '删除文章'.$title, 'type' => '文章服务']);
        $this->rest->success(['state' => $state], ErrorCodeEnum::STATUS_SUCCESS, '刪除成功！');
    }

    /**
     *  文章ajax返回模板
     */
    public function ArticleServiceAjax()
    {
        $info = AdminService::instance()->ArticleList();
        return $this->viewAjax('admin.ajaxTemplates.article_list_part')->with('info', $info);
    }

    /**
     * 文章录入
     */
    public function ArticleImport()
    {
        return $this->view("admin.article_import");
    }

    /**
     * 文章编辑
     */
    public function ArticleEdit()
    {
        if (Request::isMethod('POST')) {
            #收集信息
            $paramObj           = new stdClass();
            $paramObj->help_id  = $this->getParam('help_id');         //文章id
            $paramObj->title    = $this->getParam('title');           //文章标题
            $paramObj->content  = $this->getParam('content');         //文章内容
            $paramObj->type     = $this->getParam('type');            //文章类型

            #逻辑操作
            empty($paramObj->help_id) ?
                (AdminService::instance()->ArticleAdd($paramObj).
                LogService::instance()->write(['content' => '添加文章'.$paramObj->title, 'type' => '文章服务'])):
                (AdminService::instance()->ArticleUp($paramObj).
                LogService::instance()->write(['content' => '修改文章'.$paramObj->title, 'type' => '文章服务']));
            return Redirect::to('/admin/article_show');
        } else {
            $id = $this->getParam('help_id');
            $info = AdminService::instance()->GetArticleId($id);
            return $this->view('admin.article_import')->with('article', $info);

        }

    }

    /**
     * 会员
     * @return mixed
     * @author lzhp
     * @date 2016-04-01
     */
    public function ManageCustomer()
    {
        $info = AdminService::instance()->ManagerUser();
        return $this->view('admin.manage_customer')->with('info', $info);
    }

    /**
     * 马甲列表
     * @return mixed
     */
    public function MajiaList()
    {
        //$info=AdminService::instance()->MajiaList();
        return $this->view('admin.majia_list');
    }

    /**
     * 会员录入
     * @return mixed
     */
    public function CustomerImport()
    {
        return $this->view('admin.customer_import');
    }

    /**
     * 会员编辑
     * @return mixed
     */
    public function CustomerEdit()
    {
        if (Request::isMethod('POST')) {
            #收集信息
            $paramObj = new stdClass();
            $paramObj->user_id          =   $this->getParam('user_id');          //ID
            $paramObj->user_name        =   $this->getParam('user_name');        //姓名
            $paramObj->password         =   $this->getParam('password');         //密码
            $paramObj->mobile           =   $this->getParam('mobile');           //手机号
            $paramObj->avatar           =   $this->getParam('avatar');           //头像
            $paramObj->corporation      =   $this->getParam('corporation');      //公司名称

            //#逻辑操作
            empty($paramObj->user_id) ?
                (AdminService::instance()->CustomerAdd($paramObj).
                    LogService::instance()->write(['content' => '添加会员'.$paramObj->user_name, 'type' => '会员服务'])):
                (AdminService::instance()->CustomerUp($paramObj).
                    LogService::instance()->write(['content' => '修改会员'.$paramObj->user_name, 'type' => '会员服务']));
            return Redirect::to('/admin/manage_customer');
        } else {
            $id = $this->getParam('user_id');
            $info = AdminService::instance()->GetUserInfo($id);
            return $this->view('admin.customer_import')->with('user', $info);
        }


    }

    /**
     * 会员删除
     */
    public function CustomerDelete()
    {
        #收集信息
        $aData = new stdClass();
        $aData->user_id = $this->getParam('user_id');

        #逻辑操作
        $state = AdminService::instance()->CustomerDelete($aData);
        $user_name = AdminService::instance()->GetUserInfo($aData->user_id)->title;
        LogService::instance()->write(['content' => '删除会员'.$user_name, 'type' => '会员服务']);
        $this->rest->success(['state' => $state], ErrorCodeEnum::STATUS_SUCCESS, '刪除成功！');
    }

    /**
     * 会员ajax返回
     * @return mixed
     * @author lzhp
     * @date 2016-04-01
     */
    public function CustomerServiceAjax()
    {
        $info = AdminService::instance()->ManagerUser();
        //dd($info);die;
        return $this->viewAjax('admin.ajaxTemplates.user_list_part')->with('info', $info);
    }

    /**
     * 管理员管理
     * @return mixed
     * @author lzhp
     * @date 2016-04-04
     */
    public function ManageAdmin()
    {
        $info = AdminService::instance()->ManageAdmin();
        return $this->view('admin.manage_admin')->with('info', $info);
    }

    /**
     * 管理员添加
     * @return mixed
     * @author lzhp
     * @date 2016-04-04
     */
    public function AddAdmin()
    {
        return $this->view('admin.add_admin');
    }

    /**
     * 管理员编辑
     * @return mixed
     */
    public function EditAdmin()
    {

        if (Request::isMethod('POST')) {
            #收集信息
            $paramObj             = new stdClass();
            $paramObj->id         = $this->getParam('id');                 //ID
            $paramObj->name       = $this->getParam('name');               //姓名
            $paramObj->real_name  = $this->getParam('real_name');          //真名
            $paramObj->password   = $this->getParam('password');           //密码
            $paramObj->role_id    = $this->getParam('role_id');            //角色
            $paramObj->mobile     = $this->getParam('mobile');             //联系方式
            $paramObj->avatar     = $this->getParam('avatar');             //头像
            $paramObj->status     = $this->getParam('status');             //状态
            $paramObj->sure       = $this->getParam('sure');               //密码确认
            $paramObj->avatar_old = $this->getParam('avatar_old');


            #逻辑处理
            if(empty($paramObj->id)){
                AdminService::instance()->AdminAdd($paramObj);
                LogService::instance()->write(['content' => '添加管理员'.$paramObj->name, 'type' => '管理员管理']);
            }else{
                AdminService::instance()->AdminUp($paramObj);
                LogService::instance()->write(['content' => '修改管理员'.$paramObj->name, 'type' => '管理员管理']);
            }
            return Redirect::to('/admin/manage_admin');
        } else {
            $id = $this->getParam('id');
            $info = AdminService::instance()->GetAdminInfo($id);
            return $this->view('admin.add_admin')->with('admin', $info);
        }
    }

    /**
     * 管理员删除
     */
    public function DeleteAdmin()
    {
        #收集信息
        $aData = new stdClass();
        $aData->id = $this->getParam('id');

        $name = AdminService::instance()->GetAdminInfo($aData->id)->name;
        #逻辑操作
        $state = AdminService::instance()->DeleteAdmin($aData);
        LogService::instance()->write(['content' => '删除管理员'.$name, 'type' => '管理员管理']);
        $this->rest->success(['state' => $state], ErrorCodeEnum::STATUS_SUCCESS, '刪除成功！');
    }

    /**
     * 管理员删除ajax返回
     */
    public function AdminServiceAjax()
    {
        $info = AdminService::instance()->ManageAdmin();
        return $this->viewAjax('admin.ajaxTemplates.admin_list_part')->with('info', $info);
    }


    /**
     * 日志
     * @return mixed
     * @author lzhp
     * @date 2016-04-04
     */
    public function LogService()
    {
        $info = AdminService::instance()->LogService();
        return $this->view('admin.log_service')->with('info',$info);
    }
    /**
     *日志删除
     * @return mixed
     * @author lzhp
     * @date 2016-04-04
     */
    public function DeleteLog()
    {
        #收集信息
        $aData = new stdClass();
        $aData->log_id         =   $this->getParam('log_id');


        #逻辑操作
        $state = AdminService::instance()->DeleteLog($aData);
        $this->rest->success(['state' => $state], ErrorCodeEnum::STATUS_SUCCESS, '刪除成功！');
    }
    /**
     * 日志ajax返回
     * @return mixed
     * @author lzhp
     * @date 2016-04-04
     */
    public function LogServiceAjax()
    {
        $info = AdminService::instance()->LogService();
        return $this->viewAjax('admin.ajaxTemplates.log_list_part')->with('info', $info);
    }
    /**
     * 商家管理
     * @return mixed
     * @author lzhp
     * @date 2016-04-05
     */
    public function ManageSupplier()
    {
        $info = AdminService::instance()->ManageSupplier();
        return $this->view('admin.manage_supplier')->with('info',$info);
    }

    /**
     * 商家入驻
     * @return mixed
     * @author lzhp
     * @date 2016-04-05
     */
    public function AddSupplier()
    {
        $user = AdminService::instance()->UserSelect();
        return $this->view('admin.add_supplier')->with('user',$user);
    }
    /**
     * 编辑商家
     * @return mixed
     * @author lzhp
     * @date 2016-04-05
     */
    public function EditSupplier()
    {
        if (Request::isMethod('POST')) {
            #收集信息
            $paramObj                            =          new stdClass();
            $paramObj->supplier_id               =          $this->getParam('supplier_id');            //供应商id
            $paramObj->user_id                   =          $this->getParam('user_id');                //入驻会员ID
            $paramObj->supplier_name             =          $this->getParam('supplier_name');          //供应商名称
            $paramObj->company                   =          $this->getParam('company');                //公司名称
            $paramObj->address                   =          $this->getParam('address');                //地址
            $paramObj->address_all                   =          $this->getParam('address_all');            //详细地址
            $paramObj->phone                     =          $this->getParam('phone');                  //联系方式
            $paramObj->operate_license           =          $this->getParam('operate_license');        //营业执照
            $paramObj->show_img1                 =          $this->getParam('show_img1');              //商家展示图1
            $paramObj->show_img2                 =          $this->getParam('show_img2');              //商家展示图2
            $paramObj->show_img3                 =          $this->getParam('show_img3');              //商家展示图3
            $paramObj->operate_license_old       =          $this->getParam('operate_license_old');    //营业执照
            $paramObj->tax_license_old           =          $this->getParam('tax_license_old');        //税务登记证
            $paramObj->show_img1_old             =          $this->getParam('show_img1_old');          //商家展示图1
            $paramObj->show_img2_old             =          $this->getParam('show_img2_old');          //商家展示图2
            $paramObj->show_img3_old             =          $this->getParam('show_img3_old');          //商家展示图3
            #逻辑操作
            empty($paramObj->supplier_id) ?
                (AdminService::instance()->SupplierAdd($paramObj).
                    LogService::instance()->write(['content' => '添加商家'.$paramObj->supplier_name , 'type' => '商家服务'])):
                (AdminService::instance()->SupplierUp($paramObj).
                    LogService::instance()->write(['content' => '修改商家'.$paramObj->supplier_name , 'type' => '商家服务']));
            return Redirect::to('/admin/manage_supplier');
        } else {
            $supplier_id = $this->getParam('supplier_id');
            $info = AdminService::instance()->GeSupplierId($supplier_id);
            return $this->view('admin.add_supplier')->with('supplier', $info);
        }
    }
    /**
     * 删除商家
     * @return mixed
     * @author lzhp
     * @date 2016-04-05
     */
    public function DelSupplier()
    {
        #收集信息
        $aData = new stdClass();
        $aData->supplier_id      =   $this->getParam('supplier_id');

        $supplier_name = AdminService::instance()->GeSupplierId($aData->supplier_id)->supplier_name;
        #逻辑操作
        $state = AdminService::instance()->DelSupplier($aData);
        AdminService::instance()->UpdateUserSupplierStatus($aData);
        LogService::instance()->write(['content' => '删除商家'.$supplier_name, 'type' => '商家服务']);
        $this->rest->success(['state' => $state], ErrorCodeEnum::STATUS_SUCCESS, '刪除成功！');
    }
    /**
     * 商家ajax返回
     * @return mixed
     * @author lzhp
     * @date 2016-04-05
     */
    public function SupplierAjax()
    {
        $info = AdminService::instance()->ManageSupplier();
        return $this->viewAjax('admin.ajaxTemplates.supplier_list_part')->with('info', $info);
    }

    /**
     * 商家审核列表
     * @return mixed
     * @author lzhp
     * @date 2016-04-05
     */
    public function SupplierExamineList()
    {
        $info = AdminService::instance()->SupplierExamineList();
        return $this->viewAjax('admin.supplier_examine_list')->with('supplier_list', $info);
    }

    /**
     * 商家审核
     * @return mixed
     * @author fyl
     * @date 2016-07-13
     */
    public function SupplierExamine()
    {
        #收集信息
        $supplier_id =  $this->getParam('supplier_id');
        $supplier = AdminService::instance()->GetSupplierInfo($supplier_id);
        return $this->view('admin.supplier_examine')->with('supplier',$supplier);
        #逻辑操作
    }


    /**
     * 商家审核提交
     * @author  fyl
     * @date    2016-07-13
     */
    public function SupplierExamineAction()
    {
        #接收参数
        if(Request::isMethod('POST'))
        {
            $paramObj                       =          new stdClass();
            $paramObj->supplier_id          =          $this->getParam('supplier_id');    //审核商家ID
            $paramObj->status               =          $this->getParam('status');         //审核状态
            $paramObj->examine              =          $this->getParam('examine');        //审核描述
            #逻辑操作
            AdminService::instance()->SupplieUpdateStatus($paramObj);
            LogService::instance()->write(['content' => '审核ID为'. $paramObj->supplier_id, 'type' => '商家管理']);
            return Redirect::to('/admin/manage_supplier');
        }
    }


    /**
     *订单列表
     * @return mixed
     * @author lzhp
     * @date 2016-04-05
     */
    public function OrderList()
    {
        $info = AdminService::instance()->OrderList();
        return $this->view('admin.order_listings')->with('info',$info);
    }

    /**
     *需开发票订单
     * @return mixed
     * @author fyl
     * @date 2016-08-23
     */
    public function Invoice()
    {
        $info = AdminService::instance()->GetInvoiceList();
        return $this->view('admin.invoice_order_list')->with('info',$info);
    }

    /**
     * @return mixed
     * 完善发票信息
     */
    public function UpdateInvoice(){
        $paramObj                            =          new stdClass();
        $paramObj->invoice_id               =          $this->getParam('invoice_id');
        $paramObj->order_id                 =          $this->getParam('order_id');
        return $this->view('admin.update_invoice')->with(['order_id'=>$paramObj->order_id,'invoice_id'=>$paramObj->invoice_id]);

    }

    /**
     * @return mixed
     * 完善发票信息入库
     */
    public function UpdateInvoiceAction(){
        $paramObj                           =          new stdClass();
        $paramObj->invoice_id               =          $this->getParam('invoice_id');
        $paramObj->order_id                 =          $this->getParam('order_id');
        $paramObj->invoice_code             =          $this->getParam('invoice_code');
        $paramObj->expressage_code          =          $this->getParam('expressage_code');
        AdminService::instance()->UpdateInvoiceAction($paramObj);
        return Redirect::to('/admin/invoice');

    }



    /**
     *
     * 订单查看
     */
    public function OrderDetails(){
        if (Request::isMethod('POST')) {
            $paramObj                            =          new stdClass();
            $paramObj->order_id                 =          $this->getParam('order_id');
            $paramObj->order_status               =          $this->getParam('order_status');
            AdminService::instance()->OrderUp($paramObj);
            LogService::instance()->write(['content' => '修改订单状态' , 'type' => '订单']);
            return Redirect::to('/admin/order_list');


        }else{
            $order_id = $this->getParam('order_id');
            $order = AdminService::instance()->GetOrderDetail($order_id);
            return $this->view('admin.order_import') ->with('order', $order);
        }
    }
    //锁货处理
    public function OrderStatusAjax(){
        $paramObj                            =          new stdClass();
        $paramObj->order_id                 =          $this->getParam('order_id');
        $paramObj->order_status               =          $this->getParam('order_status');
        AdminService::instance()->OrderLock($paramObj);
        $data = AdminService::instance()->OrderUp($paramObj);
        if($data==1){
            $rs['code']=1;
        }else{
            $rs['code']=0;
        }
        return $rs;

    }
    //收款记录添加
    public function OrderPayAdd(){
        if(Request::isMethod('POST')) {
            $paramObj = new stdClass();
            $paramObj->order_id = $this->getParam('order_id');
            $paramObj->amount = $this->getParam('amount');
            $paramObj->payment = $this->getParam('payment');
            $paramObj->account = $this->getParam('account');
            $paramObj->bank_account = $this->getParam('bank_account');
            $paramObj->account_user = $this->getParam('account_user');
            $paramObj->created = $this->getParam('created');
            $paramObj->message = $this->getParam('message');
            $paramObj->enclosure = $this->getParam('enclosure');
            $paramObj->pay_trade_num = 'GLW'.time().rand(100,999);
            AdminService::instance()->OrderPayAdd($paramObj);
            LogService::instance()->write(['content' => '添加收款记录' , 'type' => '流水']);
        }else{
            $paramObj = new stdClass();
            $paramObj->order_id = $this->getParam('order_id');
            return $this->view('admin.order_pay_add')->with('order_id', $paramObj->order_id);
        }


    }
    /**
     *收款记录列表
     * OrderPayListing
     */
    public function OrderPayListing(){
        $info = AdminService::instance()->OrderList();
        return $this->view('admin.order_pay_listings')->with('info',$info);
    }
    /**
     *
     * 收款记录明细
     */
    public function OrderPayDetails(){
        $paramObj = new stdClass();
        $paramObj->order_id = $this->getParam('order_id');
        $info = AdminService::instance()->OrderPayDetails($paramObj->order_id);
        $received_amount=0;
        for($i=0;$i<count($info);$i++){
            $received_amount +=$info[$i]->amount;//实收金额

        }
        $order = AdminService::instance()->GetOrderDetail($paramObj->order_id);
        $amount_receivable = $order->amount;//应收金额
        $status = $order->order_status;//状态
        $arrears = $amount_receivable - $received_amount;//欠款
       return $this->view('admin.order_pay_details')->with(['info'=>$info,'amount_receivable'=>$amount_receivable,'received_amount'=>$received_amount,'arrears'=>$arrears,'status'=>$status]);
    }

    /**
     *询价单列表
     * @return mixed
     * @author lzhp
     * @date 2016-04-05
     */
    public function InquiryList()
    {
        $info = AdminService::instance()->InquiryList();
        return $this->view('admin.inquiry_listings')->with('info',$info);

    }
    /**
     *定制单列表
     * @return mixed
     * @author lzhp
     * @date 2016-04-05
     */
    public function CustomizeList()
    {
        $info = AdminService::instance()->CustomizeList();
        return $this->view('admin.customize_listings')->with('info',$info);

    }

    /**
     *查看定制单
     * @return mixed
     * @author fyl
     * @date 2016-06-01
     */
    public function CustomizeStatus()
    {
        $aData = new stdClass();
        $aData->customize_id   =   $this->getParam('customize_id');
        $info = AdminService::instance()->CustomizeOne($aData);
        return $this->view('admin.customize_status')->with('info',$info);

    }

    /**
     *修改定制单状态
     * @return mixed
     * @author fyl
     * @date 2016-06-01
     */
    public function CustomizeUpdate()
    {
        $aData = new stdClass();
        $aData->customize_id   =   $this->getParam('customize_id');
        $aData->status         =   $this->getParam('status');
        AdminService::instance()->CustomizeUpdate($aData);
        LogService::instance()->write(['content' => '修改ID为'.$aData->customize_id.'定制单状态', 'type' => '订单管理']);
        return Redirect::to('/admin/customize_list');

    }


    /**
     *供货单列表
     * @return mixed
     * @author lzhp
     * @date 2016-04-05
     */
    public function SupplyList()
    {
        $info = AdminService::instance()->SupplyList();
        return $this->view('admin.supply_listings')->with('info',$info);

    }

    /**
     * 广告位列表
     * @return mixed
     */
    public function AdsList()
    {
        $info = AdminService::instance()->AdsList();
        return $this->view('admin.ads_list')->with('info',$info);
    }

    /**
     * 广告位录入
     * @return mixed
     */
    public function AddAds()
    {
        return $this->view('admin.add_ads');
    }

    /**
     * 广告位编辑
     * @return mixed
     */
    public function EditAds()
    {
        if (Request::isMethod('POST')) {
            #收集信息
            $paramObj = new stdClass();
            $paramObj->ads_id           = $this->getParam('ads_id');            //广告id
            $paramObj->ads_name         = $this->getParam('ads_name');          //广告名称
            $paramObj->img              = $this->getParam('img');               //图片
            $paramObj->img_old          = $this->getParam('img_old');           //图片
            $paramObj->type             = $this->getParam('type');              //广告类型
            $paramObj->is_rec           = $this->getParam('is_rec');            //是否推荐
            $paramObj->order_by         = $this->getParam('order_by');          //排序
            $paramObj->link             = $this->getParam('link');              //链接

            #逻辑操作
            empty($paramObj->ads_id) ?
                (AdminService::instance()->AdsAdd($paramObj).
                 LogService::instance()->write(['content' => '广告位添加'.$paramObj->ads_name, 'type' => '广告位服务'])):
                (AdminService::instance()->AdsUp($paramObj));
            return Redirect::to('/admin/ads_list');
        } else {
            $ads_id = $this->getParam('ads_id');
            $info = AdminService::instance()->GetAdsInfo($ads_id);
            return $this->view('admin.add_ads')->with('ads', $info);

        }
    }

    /**
     * 广告位删除
     */
    public function DelAds()
    {
        #收集信息
        $aData = new stdClass();
        $aData->ads_id = $this->getParam('ads_id');

        $ads_name = AdminService::instance()->GetAdsInfo($aData->ads_id)->ads_name;
        #逻辑操作
        $state = AdminService::instance()->DelAds($aData);
        LogService::instance()->write(['content' => '广告位删除'.$ads_name, 'type' => '广告位服务']);
        $this->rest->success(['state' => $state], ErrorCodeEnum::STATUS_SUCCESS, '刪除成功！');
    }
    public function AdsAjax()
    {
        $info = AdminService::instance()->AdsAjax();
        return $this->viewAjax('admin.ajaxTemplates.ads_list_part')->with('info', $info);
    }


    /**
     * 资源单管理
     */
    public function ManageNewResource(){
        $product_list = AdminService::instance()->NewResource();
        return $this->view("admin.manage_new_resource")->with('product_list',$product_list);
    }

    /**
     * 资源单删除
     */
    public function NewResourceDeleteAction(){
        #收集信息
        $aData = new stdClass();
        $aData->product_id      =   $this->getParam('product_id');
        $state = AdminService::instance()->DeleteNewResource($aData);
        LogService::instance()->write(['content' => '删除资源单ID'.$aData->product_id, 'type' => '资源单管理']);
        $this->rest->success(['state' => $state], ErrorCodeEnum::STATUS_SUCCESS, '刪除成功！');
    }


    /**
     * 资源单审核
     */
    public function NewResourceExamine(){
        $aData = new stdClass();
        $aData->product_id = $this->getParam('product_id');
        $info = AdminService::instance()->NewResourceInfo($aData);
        return $this->view('admin.new_resource_examine')->with('new_resource',$info);
    }

    /**
     * 修改审核状态
     */
    public function NewResourceExamineAction(){
        #接收参数
        if(Request::isMethod('POST'))
        {
            $paramObj                       =          new stdClass();
            $paramObj->product_id           =          $this->getParam('product_id');     //审核商品ID
            $paramObj->status               =          $this->getParam('status');         //审核状态
            #逻辑操作
            $status = AdminService::instance()->NewResourceUpdateStatus($paramObj);
            LogService::instance()->write(['content' => '审核资源单ID为'. $paramObj->product_id, 'type' => '资源单管理']);
            return $status;
        }
    }

    /**
     * 资源单ajax返回
     */
    public function NewResourceServiceAjax(){
        $info = AdminService::instance()->NewResource();
        return $this->viewAjax('admin.ajaxTemplates.new_resource_list_part')->with('product_list', $info);
    }

    /**
     * 资源单浏览
     */
    public function LookExcel(){
        $filename           =         $this->getParam('filename');
        $res = [];
        Excel::load($filename, function($reader) use( &$res ) {
            $reader = $reader->getSheet(0);
            $res = $reader->toArray();
        });
        return $this->view('admin.look_excel')->with('excel', $res);
    }

    /**
     * 资源单下载
     */
    public function DownExcel(){
        $filename           =      $this->getParam('filename');
        return Response::download($filename);
    }


    /**
     * 添加资源单
     */
    public function AddExcel(){
        $file           =      $this->getParam('file');
        $clientName = $file -> getClientOriginalName();
        $entension = $file -> getClientOriginalExtension(); //上传文件的后缀.
        $newName = md5(date('ymdhis').$clientName).".".$entension;
        $path = $file -> move('resource\excel',$newName);
        dd($path);
    }




    /**
     * 邀请码入库
     */
    public function AddInviteCode() {
       return AdminService::instance()->AddInviteCode();
    }

    /**
     * js注册验证
     * @return int
     */
    public function JsVerifyRegister()
    {
        if (Request::isMethod('POST')) {
            #接收参数
            $paramObj = new stdClass();
            $paramObj->captcha           =       $this->getParam('captcha');                  //验证码
            #逻辑处理
            if(!empty($paramObj->captcha))
            {
                $data = AdminService::instance()->JsCheckCaptcha($paramObj);
                return $data;
            }
        }
    }

    /**
     * 下单列表
     */
    public function DownOrderList(){
        $info = GoodsService::instance()->ShowGoodsList();
        return $this->view("admin.down_order_list")->with('info',$info);
    }

    /**
     * 下单表单
     */
    public function DownOrderImport(){
        $paramObj = new stdClass();
        $paramObj->product_id           =       $this->getParam('product_id');                  //商品ID
        return $this->view("admin.down_order_import")->with('product_id',$paramObj->product_id);
    }

    /**
     * 手机列表
     */
    public function SelectUserMobile(){
        $paramObj = new stdClass();
        $paramObj->key_word           =       $this->getParam('key_word');                  //电话关键字
        $mobile_list = AdminService::instance()->SelectUserMobile($paramObj);
        return $mobile_list;
    }

    /**
     * 订单入库
     */
    public function DownOrderImportAction(){
        $paramObj = new stdClass();
        $paramObj->product_id           =       $this->getParam('product_id');
        $paramObj->user_id              =       $this->getParam('user_id');
        $paramObj->number               =       $this->getParam('number');
        $paramObj->pay               =       $this->getParam('pay');
        $mobile_list = AdminService::instance()->DownOrderImportAction($paramObj);
        return Redirect::to('admin/order_list');;
    }
    /**
     *
     * 品类管理
     */
    public function CategoryList(){
        $info = AdminService::instance()->ShowProductCategory();
        return $this->view('admin.product_category')->with(['category'=>$info]);

    }
    /**
     * 品类入库
     * @return mixed
     * @author fyl
     * @date 2016-04-04
     */
    public function CategoryImport()
    {
        #接收参数
        $paramObj = new stdClass();
        $paramObj->category_id = $this->getParam('category_id');
        if(!empty($paramObj->category_id)){
            $info = AdminService::instance()->SelectOneProductCategory($paramObj);
            return $this->view('admin.product_category_import')->with('category',$info);
        }else{
            return $this->view('admin.product_category_import');
        }
    }
    /**
     *
     * 品类添加
     */
    public function CategoryImportAction()
    {
        #接收参数
        if(Request::isMethod('POST'))
        {
            $paramObj                            =          new stdClass();
            $paramObj->category_id             =          $this->getParam('category_id');
            $paramObj->category_name           =          $this->getParam('category_name');
            $paramObj->fid                       =         0;
            #逻辑操作
            AdminService::instance()->AddProductCategory($paramObj);
            LogService::instance()->write(['content' => '品类添加/修改'. $paramObj->category_name, 'type' => '品类管理']);
            return Redirect::to('/admin/category_list');
        }
    }
    /**
     * 品类删除
     * @return mixed
     * @author
     * @date 2016-04-01
     */
    public function ProductCategoryDeleteAction()
    {
        #接收参数
        $paramObj = new stdClass();
        $paramObj->category_id = $this->getParam('category_id');
        $category = AdminService::instance()->SelectOneProductCategory($paramObj);
        $state = AdminService::instance()->DeleteOneProductCategory($paramObj);
        if($state){
            LogService::instance()->write(['content' => '品牌删除'. $category->category_name, 'type' => '品牌管理']);
            $this->rest->success(['state' => $state],ErrorCodeEnum::STATUS_SUCCESS,'刪除成功！');
        }else{
            $this->rest->success(['state' => $state],ErrorCodeEnum::STATUS_SUCCESS,'刪除失败！');
        }

    }
    /**
     * 品类ajax返回模板
     * @return mixed
     * @author fyl
     * @date 2016-04-05
     */
    public function ProductCategoryAjax()
    {
        $info = AdminService::instance()->ShowProductCategory();
        $this->viewAjax('admin.ajaxTemplates.product_category_part')->with('category',$info);
    }
    /*
     *
     * 规格列表
     */
    public function SpecList(){
        $info = AdminService::instance()->ShowProductSpec();

        foreach($info as $key =>$info1){
            $spec_name = AdminService::instance()->SelectCategory($info1->fid);
            $info[$key]->category_name = $spec_name->category_name;
        }

        return $this->view('admin.product_spec')->with(['spec'=>$info]);
    }
    /**
     * 规格录入
     * @return mixed
     * @author
     * @date 2016-04-04
     */
    public function SpecImport()
    {
        #接收参数
        $paramObj = new stdClass();
        $paramObj->spec_id = $this->getParam('spec_id');
        if(!empty($paramObj->spec_id)){
            $info = AdminService::instance()->SelectOneProductSpec($paramObj);
            $category = AdminService::instance()->GetCategory();
            return $this->view('admin.product_spec_import')->with(['spec'=>$info,'category'=>$category]);
        }else{
            $category = AdminService::instance()->GetCategory();
            return $this->view('admin.product_spec_import')->with('category',$category);
        }
    }
    /**
     *
     * 品类添加
     */
    public function SpecImportAction()
    {
        #接收参数
        if(Request::isMethod('POST'))
        {
            $paramObj                            =          new stdClass();
            $paramObj->spec_id                  =          $this->getParam('spec_id');
            $paramObj->spec_name                =          $this->getParam('spec_name');
            $paramObj->fid                       =          $this->getParam('f_id');
            #逻辑操作
            AdminService::instance()->AddProductSpec($paramObj);
            LogService::instance()->write(['content' => '规格添加/修改'. $paramObj->spec_name, 'type' => '规格管理']);
            return Redirect::to('/admin/spec_list');
        }
    }
    /**
     * 规格删除
     * @return mixed
     * @author
     * @date 2016-04-01
     */
    public function ProductSpecDeleteAction()
    {
        #接收参数
        $paramObj = new stdClass();
        $paramObj->spec_id = $this->getParam('spec_id');
        $category = AdminService::instance()->SelectOneProductCategory($paramObj);
        $state = AdminService::instance()->DeleteOneProductSpec($paramObj);
        if($state){
            LogService::instance()->write(['content' => '规格删除'. $category->category_name, 'type' => '规格管理']);
            $this->rest->success(['state' => $state],ErrorCodeEnum::STATUS_SUCCESS,'刪除成功！');
        }else{
            $this->rest->success(['state' => $state],ErrorCodeEnum::STATUS_SUCCESS,'刪除失败！');
        }

    }
    /**
     * 规格ajax返回模板
     * @return mixed
     * @author
     * @date 2016-04-05
     */
    public function ProductSpecAjax()
    {
        $info = AdminService::instance()->ShowProductSpec();

        foreach($info as $key =>$info1){
            $spec_name = AdminService::instance()->SelectCategory($info1->fid);
            $info[$key]->category_name = $spec_name->category_name;
        }
        $this->viewAjax('admin.ajaxTemplates.product_spec_part')->with('spec',$info);
    }


    /*
    *
    * 通知列表
    */
    public function MessageList(){
        $info = AdminService::instance()->MessageList();
        return $this->view('admin.manage_message')->with(['info'=>$info]);
    }

    /**
     *
     * 系统通知添加
     */
    public function MessageAdd()
    {
        return $this->view('admin.add_message');
    }

    /**
     *
     * 系统通知入库
     */
    public function MessageAddAction()
    {
        #接收参数
        if(Request::isMethod('POST'))
        {
            $paramObj                            =          new stdClass();
            $paramObj->title             =          $this->getParam('title');
            $paramObj->content           =          $this->getParam('content');
            #逻辑操作
            AdminService::instance()->MessageAddAction($paramObj);
            LogService::instance()->write(['content' => '通知添加'. $paramObj->title, 'type' => '系统通知']);
            return Redirect::to('/admin/message_list');
        }
    }

}





